PACKAGE = jwm
SYSCONF = $(DESTDIR)/freon/etc
MANDIR = $(DESTDIR)/freon/share/man
VERSION ?= 2.2.0
USE_NLS = yes

all:
	cd src ; $(MAKE) all ; cd ..
	cd po ; $(MAKE) all ; cd ..

install: all
	cd src ; $(MAKE) install ; cd ..
	cd po ; $(MAKE) install ; cd ..
	install -d -m 0755 $(SYSCONF)
	install -m 644 example.jwmrc $(SYSCONF)/system.jwmrc
	install -d -m 0755 $(MANDIR)/man1
	install -m 644 jwm.1 $(MANDIR)/man1/jwm.1

depend:
	cd src ; $(MAKE) depend

tarball:
	rm -f ../jwm-$(VERSION).tar.xz ;
	rm -fr ../jwm-$(VERSION) ;
	cp -r ../jwm ../jwm-$(VERSION) ;
	(cd ../jwm-$(VERSION) && $(MAKE) distclean) ;
	(cd .. && tar -cf jwm-$(VERSION).tar jwm-$(VERSION));
	rm -fr ../jwm-$(VERSION) ;
	(cd .. && xz jwm-$(VERSION).tar)

clean:
	(cd src && $(MAKE) clean)
	(cd po && $(MAKE) clean)
	rm -rf doc

distclean: clean
	rm -f *[~#] config.cache config.log config.status config.h
	rm -f Makefile src/Makefile jwm.1
	rm -fr autom4te.cache
	rm -f Makefile.bak src/Makefile.bak
	rm -fr .git .gitignore

check-gettext:
	@if test x$(USE_NLS) != "xyes" ; then \
		echo "Missing gettext. Rerun configure and check for" \
			"'checking whether to use NLS... yes'!" ; exit 1 ; fi

update-po: check-gettext
	@find src/ -name "*.c" -print | sort > po/POTFILES.in.2 ; \
	if diff po/POTFILES.in po/POTFILES.in.2 >/dev/null 2>&1 ; then \
	   rm -f po/POTFILES.in.2 ; \
	else \
	   mv po/POTFILES.in.2 po/POTFILES.in ; \
	fi
	cd po && $(MAKE) $(AM_MAKEFLAGS) update-po

update-gmo: check-gettext
	cd po && $(MAKE) $(AM_MAKEFLAGS) update-gmo

force-update-gmo: check-gettext
	touch po/*.po
	cd po && $(MAKE) $(AM_MAKEFLAGS) update-gmo

force-update-gmo-%: check-gettext
	@language=`echo $@ | sed s/force-update-gmo-//` ; \
	if test ! -f po/$$language.po ; then \
		echo "file po/$$language.po does not exist" ; exit 1 ; fi ; \
	touch po/$$language.po ; \
	cd po && $(MAKE) $(AM_MAKEFLAGS) update-gmo

.PHONY: check-gettext update-po update-gmo force-update-gmo
